package com.gy.wx_demo_mg.utils;

/**
 * @author GY
 * 2017年12月28日
 * service处理结果封装
 */
public class HResult {

    /**
     * 成功
     */
    private static final int SUCCESS = 1;
    /**
     * 失败
     */
    private static final int FAILED = 0;
    
    /**
     * 处理成功
     */
    private static final String SUCCESS_MSG = "处理成功";
    
    /**
     * 处理结果状态
     * 1:成功
     * 0:失败
     */
    private int status;
    
    /**
     * 说明
     */
    private String msg;
    
    /**
     * 处理数据结果
     */
    private Object data;
    
    private static final HResult SUCCESS_HRESULT = new HResult();
    static{
        SUCCESS_HRESULT.setStatus(SUCCESS);
        SUCCESS_HRESULT.setMsg(SUCCESS_MSG);
    }
    
    /**
     * @return
     * GY
     * 2017年12月28日
     * 使用静态对象返回 注意多线程安全
     */
    public static HResult success(){
        return SUCCESS_HRESULT;
    }

    public static HResult success(Object data){
        HResult r = new HResult();
        r.setStatus(SUCCESS);
        r.setMsg(SUCCESS_MSG);
        r.setData(data);
        return r;
    }
    
    public static HResult error(String msg){
        HResult r = new HResult();
        r.setStatus(FAILED);
        r.setMsg(msg);
        return r;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }

    public int getStatus() {
        return status;
    }

    public void setStatus(int status) {
        this.status = status;
    }
    
}
